import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yp/pages/order_create/logic.dart';

import '../../../helper.dart';
import '../logic.dart';
import 'item_widgets1.dart';

class ShopWidget extends StatefulWidget {
  int shopIndex;
  final OrderCreateLogic logic;

  ShopWidget({Key key, this.shopIndex, this.logic}) : super(key: key);

  @override
  _ShopWidgetState createState() => new _ShopWidgetState();
}

class _ShopWidgetState extends State<ShopWidget> {
  int _sum = 1;
  List jiaobiao;

  void _plus() {
    setState(() {
      _sum++;
    });
  }

  void _reduce() {
    setState(() {
      _sum--;
    });
  }

  @override
  void initState() {
    jiaobiao = widget.logic.state.cartData["multi_shop_items"][widget.shopIndex]
        ['whole_shop_promotion'];
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 30.w),
      child: GetBuilder<OrderCreateLogic>(builder: (logic) {
        return Container(
            child: Column(
          children: [
            Visibility(
                    visible: jiaobiao.length > 0,
              child: Container(
                padding: EdgeInsets.only(bottom: 10.w,top: 10.w),
                width: MediaQuery.of(context).size.width,
                decoration: new BoxDecoration(
                  color: Colors.grey[100],
                ),
                child: Row(
                  children: [
                    if (jiaobiao.length > 0)
                      Container(
                        padding:
                            EdgeInsets.symmetric(horizontal: 15.w, vertical: 6.w),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.only(
                              topLeft: Radius.circular(logic.state.angle[0]),
                              topRight: Radius.circular(logic.state.angle[1]),
                              bottomLeft: Radius.circular(logic.state.angle[2]),
                              bottomRight: Radius.circular(logic.state.angle[3])),
                          border: Border.all(
                            color: getColorFromHex(
                                logic.state.promotion_cat['frame_color']),
                            width: 1.w,
                          ),
                          color: getColorFromHex(
                              logic.state.promotion_cat['tag_fgcolor']),
                        ),
                        child: Text(
                          // tag_name_type ==1 45 0 一口价
                          logic.state.promotion_cat != null
                              ? logic.state.promotion_cat['tag_name_type'] == 1
                                  ? "${jiaobiao[0]["corner_with_param"]}"
                                  : "${jiaobiao[0]["corner_with_no_param"]}"
                              : '',
                          style: TextStyle(
                            color: getColorFromHex(
                                logic.state.promotion_cat['word_color']),
                            fontSize: 26.sp,
                            height: 1.3,
                          ),
                        ),
                      ),
                   SizedBox(
                     width: 10.w,
                   ),

                    Visibility(
                      visible: jiaobiao.length > 0,
                      child: Expanded(
                        child: new Text(
                          jiaobiao.length > 0
                              ? '${jiaobiao[0]["corner_detail"]}'
                              : '',
                          overflow: TextOverflow.ellipsis, //长度溢出后显示省略号
                          maxLines: 1,
                          style: new TextStyle(
                            fontSize: 13.0,
                            fontFamily: 'Roboto',
                            color: new Color(0xFF212121),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.only(bottom: 20.w),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    color: Color(0xfff0f0f0),
                  ),
                ),
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Image(
                    image: AssetImage("assets/images/orderStore.png"),
                    width: 36.w,
                  ),
                  SizedBox(
                    width: 5.w,
                  ),
                  Text(
                    logic.state.cartData["multi_shop_items"][widget.shopIndex]
                        ["ec_shop_name"],
                    style: TextStyle(
                        fontSize: 26.sp,
                        color: Color(0xff333333),
                        fontWeight: FontWeight.bold),
                  ),
                ],
              ),
            ),
            Container(
              decoration: BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  ListView.builder(
                    itemBuilder: (ctx, index) {
                      return ItemWidget1(
                          shopIndex: widget.shopIndex,
                          goodsListIndex: index,
                          logic: logic);
                    },
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: logic
                        .state
                        .cartData["multi_shop_items"][widget.shopIndex]
                            ["cart_item_list"]
                        .length,
                  ),
                ],
              ),
            ),
          ],
        ));
      }),
    );
  }
}
